<?php
class MyCache
{

    private $mmc = null;
    private $group = null;
    private $version = 1;
    function __construct($group){
        if(!class_exists('mmcache')){
            $this->mmc = false;
            return;
        }
        $this->mmc = new memcache();
        $this->mmc->addServer('localhost', 11211);
        //$this->mmc->addServer('10.0.1.210', 11211);
        $this->group = $group;
        $this->version = $this->mmc->get('version_'.$group);
    }
    function set($key, $var, $expire=3600){
        if(!$this->mmc)return;
        return $this->mmc->set($this->group.'_'.$this->version.'_'.$key, $var, $expire);
    }
    function get($key){
        if(!$this->mmc)return;
        return $this->mmc->get($this->group.'_'.$this->version.'_'.$key);
    }
    function incr($key, $value=1){
        if(!$this->mmc)return;
        return $this->mmc->increment($this->group.'_'.$this->version.'_'.$key, $value);
    }
    function decr($key, $value=1){
        if(!$this->mmc)return;
        return $this->mmc->decrement($this->group.'_'.$this->version.'_'.$key, $value);
    }
    function delete($key){
        if(!$this->mmc)return;
        return $this->mmc->delete($this->group.'_'.$this->version.'_'.$key);
    }
    function flush(){
        if(!$this->mmc)return;
        ++$this->version;
        $this->mmc->set('version_'.$this->group, $this->version);
    }
}
?>